package com.yc.zyz.servlet;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.yc.mybatis.damai.MyBatisHelper;
import com.yc.zyz.entity.Task;
import com.yc.zyz.mapper.TaskMapper;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/7/28
 * Email haijunzhou@hnit.edu.cn
 */
@WebServlet("/queryTask")
public class QueryTaskServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String s = req.getParameter("page");
        int ipage = 1;
        if(s!=null){
            ipage = Integer.valueOf(s);
        }
        SqlSession session = MyBatisHelper.getSession();
        TaskMapper taskMapper = session.getMapper(TaskMapper.class);
        IPage page = Page.of(ipage, 8);
        page = taskMapper.selectPage(page,null);
        Gson gson = new Gson();
        String json = gson.toJson(page);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().println(json);
        session.close();
    }
}
